cdef extern from "string.h":
	void *memcpy(void *dest, void *src, size_t n)
	size_t strlen(char *s)


#TODO, from octodb.h
cdef extern from "fdb.h":	
	ctypedef void column_t
	ctypedef void condition_t
	ctypedef void database_t
	ctypedef void query_t
	ctypedef void result_t
	ctypedef void table_t
	ctypedef void transaction_t

	ctypedef int result_e
	ctypedef int query_type_e

	ctypedef int (*query_callback_f)(query_t *, void *)

	# Necessary conditionals
	condition_t *condition_callback_new(query_callback_f, void *)
	condition_t *condition_predicate_new(int, char *, int, ...)
	condition_t *condition_predicate_new_list(int, char *, int, size_t *, char **)
	condition_t *condition_negate(condition_t *)
	void condition_destroy(condition_t *)

	# Database
	database_t *database_open(char *)
	int database_table_create(database_t *, table_t *)
	int database_table_drop(database_t *, char *)
	table_t *database_table_get(database_t *, char *)
	void database_close(database_t *)

	# Transaction processing
	transaction_t *transaction_begin(database_t *, int)
	int transaction_commit(transaction_t *)
	int transaction_rollback(transaction_t *)

	# Query mechanism
	query_t *query_new(transaction_t *)
	result_e query_data_get(query_t *, int, char **, size_t *)
	result_e query_column_get_id(query_t *, char *, int *)
	result_e query_datatype_args_get(query_t *, int, char ***, int *)
	result_e query_datatype_get(query_t *, int, char **)
	result_e query_execute(query_t *)
	result_e query_finalize(query_t *)
	result_e query_prepare(query_t *, query_type_e, char *)
	result_e query_step(query_t *)
	void query_append_conditions(query_t *, ...)
	void query_append_conditions_list(query_t *, int, condition_t **)
	void query_data_set(query_t *,...)
	void query_data_set_list(query_t *, char **, size_t *)
	void query_destroy(query_t *)
	void query_update_callback(query_t *, query_callback_f, void *)

	# Result processing
	int result_eod(result_e)
	int result_error(result_e)
	char *result_text(result_e)
	int result_ok(result_e)

	# Column manipulation
	column_t *column_new(char *, char *, ...)
	column_t *column_new_list(char *, char *, char **, int)
	void column_destroy(column_t *)

	# Table manipulation
	table_t *table_new(char *)
	void table_add_column(table_t *, column_t *)
	int table_get_column_count(table_t *)
	char *table_get_column_datatype(table_t *, int)
	int table_get_column_datatype_args(table_t *, int , char ***, int *)
	int table_get_column_id(table_t *, char *)
	char *table_get_column_name(table_t *, int)
	void table_destroy(table_t *)

cdef class OctoDBDatabase:
	cdef database_t *_database
	cdef char *_path

cdef class OctoDBTable:
	cdef char *name
	cdef list columns
	cdef table_t *_table

cdef class OctoDBColumn:
	cdef char *name
	cdef char *datatype
	cdef list dtargs
	cdef column_t *_column

cdef class OctoDBTransaction:
	cdef int isolation
	cdef database_t *_database
	cdef transaction_t *_transaction

cdef class OctoDBRow:
	cdef query_t *_query

cdef class OctoDBQuery:
	cdef query_t *_query
	cdef bool _executed
	cdef object conditions

cdef class OctoDBCondition:
	cdef condition_t *_condition
	cdef bool positive

cdef class OctoDBConditionPredicate(OctoDBCondition):
	cdef int column_id
	cdef char *predname
	cdef list args

cdef class OctoDBConditionCallback(OctoDBCondition):
	cdef object callback
	cdef tuple callback_data
